package tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/empdb" +
                        "?characterEncoding=utf8" +
                        "&serverTimezone=Asia/Shanghai",
                "root","root");
        Statement s = conn.createStatement();
        //插入数据
        //s.executeUpdate("insert into emp(name)values('Tom')");
        //修改数据
        //s.executeUpdate("update emp set name='Jerry' where name='Tom'");
        //删除数据
        //s.executeUpdate("delete from emp where name='Jerry'");
        //查询数据   ResultSet结果集
        ResultSet rs = s.executeQuery("select name,sal from emp");
        //遍历结果集对象 next()方法判断是否有下一条数据 有返回true游标移动一格,没有返回false
        while(rs.next()){
            String name = rs.getString("name");
            double sal = rs.getDouble("sal");
            System.out.println(name+":"+sal);
        }
        System.out.println("执行完成!");
        conn.close();

    }
}
